/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jard.webshop.jsfbeans;

import jard.webshop.nbp.Product;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import java.io.Serializable;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ActionEvent;

/**
 *
 * @author Disaia
 */
@ManagedBean(name = "productController")
@RequestScoped
public class ProductController implements Serializable {

    @ManagedProperty(value = "productBacking")
    private ProductBacking backingBean;
    
    @ManagedProperty(value = "#{cartModel}")
    private CartModel cartModel;

    /** Creates a new instance of ProductController */
    public ProductController() {
    }
    
    public ProductBacking getBackingBean(){
        return this.backingBean;
    }
        public void setBackingBean(ProductBacking backingBean){
        this.backingBean = backingBean;
    }

    public CartModel getCartModel() {
        return cartModel;
    }

    public void setCartModel(CartModel cartModel) {
        this.cartModel = cartModel;
    }


    public void addToCart(ActionEvent evt) {
        cartModel.addProduct(backingBean.getProduct());
    }
    
    public String saveProduct(){
        System.out.println("Saving product as: " + this.backingBean.getProduct().getName() + "");
        backingBean.saveProduct();
        return "editproducts";
    }
}
